package com.example.dee.service.impl;

import com.example.dee.dao.SysDAO;
import com.example.dee.pojo.*;
import com.example.dee.pojo.vo.ResponseJSON;
import com.example.dee.service.SysService;
import com.example.dee.util.RandomUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @ClassName SysServiceImpl
 * @创建人 李劲松
 * @创建时间 2022/7/20 10:26
 * @描述 A机构管理员对数据库操作接口的实现类
 */
@Service
public class SysServiceImpl implements SysService {
    @Resource
    SysDAO sysDAO;

    @Override
    public CarData selectCarData(String id) {
        return sysDAO.selectCarData(id);
    }

    @Override
    public void updateCarDataState(String id , ResponseJSON responseJSON, String date) {
        sysDAO.updateCarDataState(id,responseJSON.getState(),responseJSON.getInfo(),date);
    }

    @Override
    public int addCarData(String id, String enTime, String enTollStationName, String exTime, String exTollStationName, String vehicleId,int vehicleType, Double fee) {
        return sysDAO.addCarData(id, enTime, enTollStationName, exTime, exTollStationName, vehicleId,vehicleType, fee);
    }

    @Override
    public int deleteCarData(String id) {
        return sysDAO.deleteCarData(id);
    }

    @Override
    public String selectSerialData() {
        return sysDAO.selectSerialData();
    }

    @Override
    public int selectSerial() {
        return sysDAO.selectSerial();
    }

    @Override
    public void updateSerial(int serial, String serialData) {
        sysDAO.updateSerial(serial,serialData);
    }

    @Override
    public String selectCommand() {
        return sysDAO.selectCommand();
    }

    @Override
    public int updateCommand(String command) {
        return sysDAO.updateCommand(command);
    }

    @Override
    public int addCarRecord(CarData carData, String func, int sysId) {
        return sysDAO.addCarRecord(carData.getId(),carData.getEnTime(),carData.getEnTollStationName()
        ,carData.getExTime(),carData.getExTollStationName(),carData.getVehicleId(),carData.getVehicleType()
        ,carData.getFee(),carData.getState(),carData.getDesc(),func,new Date(),sysId);
    }

    @Override
    public int addRecord(CarData carData, String receiveDesc, int sysId) {
        String upDesc = "";
        if("0".equals(carData.getState())){
            upDesc = "首次上传";
        }else if("1".equals(carData.getState())){
            upDesc = "重复上传";
        }else if("2".equals(carData.getState())){
            upDesc = "修改后上传";
        }else if("3".equals(carData.getState())){
            upDesc = "上传失败后重传";
        }
        return sysDAO.addRecord(carData.getId(),carData.getEnTime(),carData.getEnTollStationName()
                ,carData.getExTime(),carData.getExTollStationName(),carData.getVehicleId(),carData.getVehicleType()
        ,carData.getFee(),upDesc,receiveDesc,new Date(),sysId);
    }

    @Override
    public int updateRecord(String info,String id) {
        return sysDAO.updateRecord(info,id);
    }

    @Override
    public List<CarData> selectCarDataAll() {
        return sysDAO.selectCarDataAll();
    }

    @Override
    public List<CarData> selectCarDataByState(String state,int begin,int showNum) {
        return sysDAO.selectCarDataByState(state,begin,showNum);
    }

    @Override
    public List<CarData> selectCarDataByUp(int begin,int showNum) {
        return sysDAO.selectCarDataByUp(begin,showNum);
    }

    @Override
    public List<Record> selectRecord(String data,int begin,int showNum) {
        return sysDAO.selectRecord(data,begin,showNum);
    }

    @Override
    public List<CarRecord> selectCarRecord(String today , int begin,int showNum) {
        return sysDAO.selectCarRecord(today,begin,showNum);
    }

    @Override
    public int updateCarData(String id, Double fee) {
        return sysDAO.updateCarData(id,fee,new Date(),"已修改");
    }

    @Override
    public int getCountByTable(String table) {
        return sysDAO.getCountByTable(table);
    }

}
